<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>菜单列表</title>
    <link rel="stylesheet" type="text/css" href="/static/h+/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/h+/css/font-awesome.min93e3.css?v=4.4.0">
    <!-- Data Tables -->
    <link rel="stylesheet" type="text/css" href="/static/h+/css/plugins/dataTables/dataTables.bootstrap.css">
    <link rel="stylesheet" type="text/css" href="/static/h+/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/h+/css/style.min.css?v=4.1.0">
    <link rel="stylesheet" type="text/css" href="/static/layer/skin/layer.css">
    <link rel="stylesheet" type="text/css" href="/static/paging/paging.css">
    <style type="text/css">
        .sort_span{display: block;width: 80px;}
        .sort_txt{display: none;width: 80px;height: 18px;outline: none;border: 1px solid #1ab394;}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
  <div class="row">
    <div class="col-sm-12">
      <div class="ibox float-e-margins">
        <div class="ibox-title">
          <input type="button" class="btn btn-sm btn-primary" value="添加" onclick="location.href='{:url(\'add\')}'">
        </div>
        <div class="ibox-content">
          <table class="table table-striped table-bordered table-hover dataTables-example">
            <thead>
            <tr>
              <th>序号</th>
              <th>标识</th>
              <th>名称</th>
              <th>链接</th>
              <th>左则显示</th>
              <th style="width: 100px;">排序</th>
              <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {foreach $list as $key=>$item}
            <tr>
              <td>{$key+1}</td>
              <td>{$item.identity}</td>
              <td>{$item.title}</td>
              <td>{$item.url}</td>
              <td>{if($item.is_hide)}否{else/}是{/if}</td>
              <td><span class="sort_span">{$item.sort}</span><input type="text" class="sort_txt" value="{$item.sort}" data-id="{$item.id}"></td>
              <td><a href="javascript:;" data-action="del" data-id="{$item['id']}">删除</a> | <a href="/menu/edit?id={$item['id']}">编辑</a></td>
            </tr>
            {/foreach}
            </tbody>
            <footer>
            <tr>
              <td colspan="100"><div class="dataTables_paginate paging_simple_numbers paging_page">{$pages}</div></td>
            </tr>
            </footer>
          </table>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
<script type="text/javascript" src="/static/h+/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/layer/layer.js"></script>
<script type="text/javascript" src="/static/paging/paging-min.js"></script>
<script type="text/javascript">
    $(function(){
        $('.sort_span').click(function(){
            $(this).css('display', 'none').next('.sort_txt').css('display', 'block').select()
        });
        $('.sort_txt').blur(function(){
            var $this = $(this);
            $.ajax({
                type: 'post', dataType: 'json', cache: false,
                url: '{:url("operatesort")}',
                data: {'id': $this.data('id'), 'sort': $this.val()},
                success: function($data){
                    if ($data.status == 0) {
                        layer.msg($data.info, {icon: 6, time: 1000}, function(){
                            $this.prev('.sort_span').css('display', 'block').html($this.val());
                            $this.css('display', 'none');
                        });
                    }else{
                        layer.msg($data.info, {icon: 5, time: 1000})
                    }
                }
            })
        })
        $('a[data-action]').click(function(){
            if ($(this).data('action') == 'del') {
                $id = $(this).data('id');
                layer.confirm('确实要删除吗？',function(){
                    $.ajax({
                        type: 'post', cache: false, dataType: 'json',
                        url: '{:url("del")}',
                        data: {'id': $id},
                        success: function(data){
                            if (data.status == 0) {
                                layer.msg(data.info, {icon: 6, time: 1000}, function(){
                                    location.href = '{:url("lists")}';
                                });
                            }else{
                                layer.msg(data.info, {icon: 5, time: 1000});
                            }
                        }
                    });
                });
            }
        });
    });
</script>
</html>